<?php
/*
 * @Author: lokei
 * @Date: 2022-08-08 09:23:25
 * @LastEditors: lokei
 * @LastEditTime: 2023-06-25 12:03:07
 * @Description: 
 */

namespace App\Http\Controllers\Platform\Conf;

use App\Common\Tools\ResultTool;
use App\Http\Controllers\Controller;
use App\Models\Pay\Conf\ConfModel;
use App\Models\Platform\Alias\AliasModel;
use App\Models\Platform\ConfModel as PlatformConfModel;
use App\Models\Widget\ConfModel as WidgetConfModel;
use App\Models\Widget\ThemePersonModel;
use Illuminate\Support\Facades\Schema;

class InitController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    //

    public function get()
    {
        $res = ResultTool::success();

        $platform_conf = PlatformConfModel::first();
        if (is_null($platform_conf)) {
            $platform_conf = new PlatformConfModel();
            $platform_conf->save();
        }
        $res['data']['platform_conf'] = !is_null($platform_conf) ? [
            'logo' => $platform_conf->logo,
            'name' => $platform_conf->name,
            'tel' => $platform_conf->tel
        ] : null;

        if (Schema::hasTable('alias')) {
            $alias = AliasModel::first();
            if (is_null($alias)) {
                $alias = new AliasModel();
                $alias->store = '商家门店';
                $alias->save();
                $alias = AliasModel::first();
            }
            $res['data']['alias'] = $alias;
        }

        return $res;
    }
}
